/*
 * aesUtils.h
 *
 *  Created on: Feb 21, 2010
 *      Author: Łukasz Spintzyk
 */

#ifndef AESUTILS_H_
#define AESUTILS_H_

#include "ph.h"


#include <stdint.h>
typedef byte u8;
typedef uint32_t u32;

#define GETU32(pt) (((u32)(pt)[3] << 24) ^ ((u32)(pt)[2] << 16) ^ ((u32)(pt)[1] <<  8) ^ ((u32)(pt)[0]))
#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }


extern const uint32_t TE0[256];
extern const uint32_t TE1[256];
extern const uint32_t TE2[256];
extern const uint32_t TE3[256];

extern const  byte SBOX[256];
extern byte SBOX_INV[256];
extern const byte INVMIXTAB[4][4];
extern const uint32_t Rcon[60];
extern const byte NR[3][3];// [Nk] [Nb]
extern const byte MIXTAB[4][4];
extern const byte SHIFT_NB[3][4][8];
const unsigned int SHIFT_NB_SIZE = 3*4*8*sizeof(byte);
extern const uint32_t RCON[60];

#define XTIME(x) ( ( x <<  1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )

enum NB
{
	NB_4 = 0, NB_6 = 1, NB_8 = 2
};

#define C0(x) 0
#define C1(x) 1
#define C2(x) ( (x) == NB_8 ? 3 : 2 )
#define C3(x) ( (x) == NB_8 ? 4 : 3 )

#define BLOCK_SIZE(nb) ((nb) == NB_4 ? 16 : (((nb) == NB_6 ) ? 24 : 32))


uint32_t rotByte(uint32_t data);

uint32_t subByte(uint32_t data);

uint32_t subRotByte(uint32_t data);

#endif /* AESUTILS_H_ */
